package com.itheima.info.manager.system.dao;

import com.itheima.info.manager.system.domain.Student;
import com.itheima.info.manager.system.domain.Teacher;

public class TeacherDao {
    private static Teacher[] teachers=new Teacher[10];
    //添加老师
    public boolean addTeacher (Teacher teacher){
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher1 = teachers[i];
            if (teacher1==null){
            teachers[i]=teacher;
            return true;
            }
        }
        return false;
    }

    //删除老师
    public void deleteTeacher (String sid){
        int getindex = getindex(sid);
        teachers[getindex]=null;
    }
    //修改老师
    public void updateTeacher(String sid,Teacher teacher){
        int getindex = getindex(sid);
        teachers[getindex]=teacher;
    }
    //查看老师
    public Teacher[] findAllTeachers(){
        return teachers;
    }
    //根据工号找索引
    public int getindex(String sid){
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher!=null&&teacher.getSid().equals(sid)){
                return i;
            }
        }
        return -1;
    }
}
